﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ForthSharp
{
    enum TokenType
    {
        NUMBER,
    }

    struct Token
    {
        public TokenType type {get; set;}
        public string text {get; set;}
    }

    class Lexer
    {
        public readonly Dictionary<TokenType, Regex> REGEX_MAPPING = new Dictionary<TokenType, Regex> {
            {TokenType.NUMBER, new Regex("\\d*", RegexOptions.Compiled)}
        };

        public IEnumerable<Token> Lex(string text)
        {
            string[] split_text = text.Split(null);

            foreach (string s in split_text)
            {
                foreach (var kvp in REGEX_MAPPING)
                {
                    if (kvp.Value.IsMatch(s))
                    {
                        yield return new Token { type = kvp.Key, text = s };
                        break;
                    }
                }
            }
        }
    }
}
